package com.example.kindergarten.controller

import cn.dev33.satoken.secure.SaSecureUtil
import com.example.kindergarten.dto.HelloInfoDto
import com.example.kindergarten.dto.HelloIdDto
import com.example.kindergarten.dto.IdRequiredDto
import com.example.kindergarten.services.HelloService
import com.example.kindergarten.util.ResultResponse
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import javax.validation.Valid


@RestController
@Api(tags = ["hello模块"])
class HelloController {
    @Autowired
    lateinit var helloService: HelloService

    @PostMapping("/auth")
    fun sayHello( @RequestBody @Valid param: HelloInfoDto): String {
        val privateKey =
            "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKaPemDozMfM1H6kJvjUFEHqvG1aLaoi4LLFzqaHF0V1d7tLiG/P/nVZoKQ4Xn9QgZi4AwtSGz2qvaoisAC2kEtV9XNJX9CLrlEeIlNCfbJcunKEkfIy7Rh9dl5X23/yz+ds8XssrhVpseGokvZaPY7b7l6q6KihU0Sqtgzffju7AgMBAAECgYBvGwSSgpifqyYQeGW61JXSxsf81gviEzP6bPMFqNXAMrS0zpTrqT5ff3MmOKfom4ZnnlABjDq5rxyn0k2/nAix9D/pzAr9EgtCOlsmjCzfNtDuGciz7ZwGTqMhg5ls5ajkURYMn3GFYgi4oGfcqAMDfLxHIt1xO9Muj4sU8tgnEQJBANzSJMbNlJFbl9aBeD3yOqs/PxAPjHyrzhFHUP4uAYoWwGHVQ6qCC9LcNV/OZ0swC78H9eJMEnI4yTuywEF8agMCQQDBGGcfVt33x59VtZ11jea70OPbuERU7+CcBIOv0sroyrVersXU+Qu3rHMnZHnKhhTCzanLXcs5hMB1Rl6H2pXpAkAiMjTZyJpaTEneQRyC01E8lcXJUe8am2yFBntHcY5xeQZ/4AvjitIT7GAjnw4l+aHICo6MZeVxZNPc99iIC6FLAkEAtYioomj7Y1Az9tM4hmTy0A3xugaBj0y5YFRKLYlCJBs26h3rdW7x2irxU859Ra5KZF4PzFaQkbHBcj/G7XfNyQJAXSqNBWPgpDocLmRPhxeIzZA68UlBXR/ULw3t7iEmVe9duZiCbCuqVnJGTEEE224qURzcTA64R81/dbfg8l7cjw=="
        val publicKey =
            "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmj3pg6MzHzNR+pCb41BRB6rxtWi2qIuCyxc6mhxdFdXe7S4hvz/51WaCkOF5/UIGYuAMLUhs9qr2qIrAAtpBLVfVzSV/Qi65RHiJTQn2yXLpyhJHyMu0YfXZeV9t/8s/nbPF7LK4VabHhqJL2Wj2O2+5equiooVNEqrYM3347uwIDAQAB"
        val text = "这是一段文本"
        val ciphertext = SaSecureUtil.rsaEncryptByPublic(publicKey, text)
        val text2 = SaSecureUtil.rsaDecryptByPrivate(privateKey, ciphertext)
        println(text2)
        println(param)
        return "asdadsadasdad"
    }

    @PostMapping(value = ["/testPostValid"])
    fun testPostValidException(@RequestBody @Validated vo: HelloIdDto): ResultResponse{
//        val u: List<User> = userMapper.selectAll()
        return ResultResponse.success(vo)
    }

    @PostMapping("/user")
    @ApiImplicitParam(name = "user", value = "姓名", required = true)
    @ApiOperation(value = "向客人问好")
    fun insertUser(@RequestBody @Valid param: IdRequiredDto): ResultResponse {
        return helloService.getUserById("1")
    }

    @ApiImplicitParam(name = "name", value = "姓名", required = true)
    @ApiOperation(value = "向客人问好")
    @GetMapping("/sayHi")
    fun sayHi(@RequestParam(value = "name") name: String): ResultResponse {
        return ResultResponse.success("asdasd")
    }
}